import request from "@/utils/request";
import {curCommunity} from "@/api/common";
import qs from "qs";
import {param} from "jquery";

export function getCommunityPersons(params) {
  return request({
    url: "/cgi-bin/entry.cgi/system/para/webPage",
    method: "get",
    params,
    curCommunity,
  });
}

// 人脸人员清单列表
export function getFacePersonsListApi(params) {
  return request({
    url: "/cgi-bin/entry.cgi/event/face-list?search=condition2",
    method: "put",
    data: params,
  });
}

// 人脸人员清单列表姓名查询
export function getFacePersonsListNamesApi(params) {
  return request({
    url: "/cgi-bin/entry.cgi/event/face-list?search=condition2",
    method: "put",
    data: params,
  });
}

// 人员管理导出
export function faceListExportUrlApi(data) {
  return request({
    url: "/cgi-bin/entry.cgi/event/face-list-export-url",
    method: "post",
    data: data,
  });
}

// 删除全部人员
export function clearAllUserApi(data) {
  return request({
    url: "/cgi-bin/entry.cgi/event/clear-all-user",
    method: "delete",
    data: data,
  });
}

// 获得UI密码
export function getUiPasswordApi(data) {
  return request({
    url: "/cgi-bin/entry.cgi/system/ui-password",
    method: "get",
    data: data,
  });
}

// 修改UI密码
export function editUiPasswordApi(data) {
  return request({
    url: "/cgi-bin/entry.cgi/system/ui-password",
    method: "post",
    data: data,
  });
}

// 登录记录查询
export function getLoginRecordsApi(data) {
  return request({
    url: "/cgi-bin/entry.cgi/system/login-records",
    method: "post",
    data: data,
  });
}

// 登录记录删除
export function delLoginRecordsApi(data) {
  return request({
    url: "/cgi-bin/entry.cgi/system/login-record-delete-batch",
    method: "post",
    data: data,
  });
}

// 删除全部登录记录
export function delLoginRecordsAllApi(data) {
  return request({
    url: "/cgi-bin/entry.cgi/system/login-record-all",
    method: "delete",
    data: data,
  });
}

// 导出登录记录
export function loginRecordsExportUrlApi(data) {
  return request({
    url: "/cgi-bin/entry.cgi/system/login-records-export-url",
    method: "post",
    data: data,
  });
}

// 开门记录查询
export function getOpenDoorRecordsApi(data) {
  return request({
    url: "/cgi-bin/entry.cgi/event/dooropen_info_list",
    method: "post",
    data: data,
  });
}

// 删除单个开门记录
export function delDoorRecordsSingleApi(data) {
  return request({
    url: "/cgi-bin/entry.cgi/event/single_doorinfo_del",
    method: "post",
    data: data,
  });
}


// 删除全部开门记录
export function delDoorRecordsAllApi(data) {
  return request({
    url: "/cgi-bin/entry.cgi/event/opendoor-all",
    method: "delete",
    data: data,
  });
}

// 新增人脸人员
export function addFacePersonsApi(data) {
  return request({
    url: "/cgi-bin/entry.cgi/event/face",
    method: "post",
    data,
  });
}

// 修改人脸人员
export function editFacePersonsApi(data, id) {
  return request({
    url: "/cgi-bin/entry.cgi/event/face/" + id,
    method: "post",
    data,
  });
}

// 获取人员信息是否成功
export function getFacePersonsApi(id, timeSummary) {
  return request({
    url: "/cgi-bin/entry.cgi/event/face/" + id + `?timestamp=${timeSummary}`,
    method: "get",
  });
}

// 删除人脸人员
export function delFacePersonsApi(data) {
  return request({
    url: "/cgi-bin/entry.cgi/event/person-info-delete",
    method: "post",
    data
  });
}

// 上传人脸人员图片
export function personsUploadApi(data, path) {
  return request({
    url: "/cgi-bin/entry.cgi/event/face-picture?path=" + path,
    method: "post",
    data,
  });
}

// 修改抓拍记录图片
export function personsUploadZhuapaiApi(data, path) {
  return request({
    url: "/cgi-bin/entry.cgi/event/face-picture?copy-path=" + path,
    method: "put",
    data,
  });
}

// 删除全部抓拍记录
export function delSnapshotAllApi(data) {
  return request({
    url: "/cgi-bin/entry.cgi/event/snapshot-all",
    method: "delete",
    data,
  });
}

// 批量删除抓拍记录
export function delSnapshotBatchApi(data) {
  return request({
    url: "/cgi-bin/entry.cgi/event/snapshot-delete-batch",
    method: "put",
    data,
  });
}

// 人脸抓拍记录
export function snapshotRecordListApi(data, path) {
  return request({
    url: "/cgi-bin/entry.cgi/event/snapshot-record",
    method: "put",
    data,
  });
}

// 人脸抓拍记录删除1-1
export function delSnapshotRecordListApi(data) {
  return request({
    url: "/cgi-bin/entry.cgi/event/snapshot-record?delete=" + data,
    method: "delete",
  });
}

// 人脸抓拍记录删除1-2
export function del2SnapshotRecordListApi(data) {
  return request({
    url: "/cgi-bin/entry.cgi/event/snapshot-record",
    method: "post",
    data,
  });
}

// 抓拍记录导出
export function snapshotRecordExportApi(data) {
  return request({
    url: "/cgi-bin/entry.cgi/event/snapshot-record-export-url",
    method: "post",
    data,
  });
}

/* // 视频导出测试
export function exportTestApi(data) {
  return request({
    url: "/tmp/record_export/1.mp4",
    method: "get",
    data,
  });
} */

// 控制记录删除1-1
export function delSnapshotControlListApi(params) {
  return request({
    url: "/cgi-bin/entry.cgi/event/control-record?" + params,
    method: "delete",
  });
}

// 删除全部识别记录
export function delRecordAllApi() {
  return request({
    url: "/cgi-bin/entry.cgi/event/record-all",
    method: "delete",
  });
}

export function controlRecordExportUrlApi(data) {
  return request({
    url: "/cgi-bin/entry.cgi/event/control-record-export-url",
    method: "POST",
    data,
  });
}

// 控制记录删除1-2
export function del2SnapshotControlListApi(data) {
  return request({
    url: "/cgi-bin/entry.cgi/storage/delete",
    method: "post",
    data,
  });
}

// 人脸控制记录搜索1
export function controlRecordListApi(data) {
  return request({
    url: "/cgi-bin/entry.cgi/event/control-record?search=condition2",
    method: "put",
    data,
  });
}

// 人脸控制记录搜索2
export function controlRecordListNameApi(data) {
  return request({
    url: "/cgi-bin/entry.cgi/event/control-record?search=condition2",
    method: "put",
    data,
  });
}

// ===========多张上传文件==========
// 获取最后一个上传文件
export function getLastFaceApi() {
  return request({
    url: "/cgi-bin/entry.cgi/event/last-face",
    method: "get",
  });
}

// 获取文件等待
export function getFaceWaitingApi(data = new Date().getTime()) {
  return request({
    url: "/cgi-bin/entry.cgi/event/face-waiting?timestamp=" + data,
    method: "get",
  });
}

//根据id检测上传失败数量
export function getFaceCheckIdsApi(data) {
  return request({
    url: "/cgi-bin/entry.cgi/event/check-face?id=" + data.id,
    method: "post",
    data,
  });
}

export function getBase64(file) {
  return new Promise(function (resolve, reject) {
    let reader = new FileReader();
    let imgResult = "";
    reader.readAsDataURL(file);
    reader.onload = function () {
      imgResult = reader.result;
    };
    reader.onerror = function (error) {
      reject(error);
    };
    reader.onloadend = function () {
      resolve(imgResult);
    };
  });
}

//获取错误列表
export function getErrorList(data) {
  return request({
    url: "/cgi-bin/entry.cgi/event/batch-add-error-list",
    method: "post",
    data,
  });
}

//删除错误信息 -- 单个
export function doDelError(data) {
  return request({
    url: `/cgi-bin/entry.cgi/event/batch-add-error-list/${data}`,
    method: "delete",
  });
}

//删除错误信息 -- 多个
export function doDelErrorMultiple(data) {
  return request({
    url: `/cgi-bin/entry.cgi/event/batch-add-error-batch-delete`,
    method: "post",
    data
  });
}
//删除错误信息 -- 清空
export function clearAllErrors(data) {
  return request({
    url: `/cgi-bin/entry.cgi/event/clear-all-batch-add-error`,
    method: "delete",
  });
}

//获取错误列表(image)
export function getErrorList2(data) {
  return request({
    url: "/cgi-bin/entry.cgi/event/identity-picture-list",
    method: "post",
    data,
  });
}

//删除错误信息(image) -- 单个
export function doDelError2(data) {
  return request({
    url: `/cgi-bin/entry.cgi/event/identity-picture/${data}`,
    method: "delete",
  });
}

//删除错误信息(image) -- 多个
export function doDelErrorMultiple2(data) {
  return request({
    url: `/cgi-bin/entry.cgi/event/identity-picture-batch-delete`,
    method: "post",
    data
  });
}
//删除错误信息(image) -- 清空
export function clearAllErrors2(data) {
  return request({
    url: `/cgi-bin/entry.cgi/event/clear-all-identity-picture`,
    method: "delete",
  });
}

//下载人员模板

export function getPersonTemplate(data) {
  return request({
    url: `/template/batch_add_template.xlsx`,
    method: "get",
    responseType: "blob",
  });
}

//upload人员模板

export function uploadPerson(data) {
  return request({
    url: `/cgi-bin/entry.cgi/event/impl-excel`,
    method: "post",
    data
  });
}
//upload图片

export function uploadImage(data) {
  return request({
    url: `/cgi-bin/entry.cgi/event/impl-excel-picture`,
    method: "post",
    data
  });
}


//upload图片
export function predictSubmitStatusApi(data) {
  return request({
    url: `/cgi-bin/entry.cgi/event/impl-excel-available`,
    method: "post",
    data
  });
}

//人脸库容量
export function getFaceCountApi(data) {
  return request({
    url: "/cgi-bin/entry.cgi/event/faceCount",
    method: "get",
  });
}




